<template>
  <el-dialog title="编辑区段" :modelValue="visiable" width="50%" @close="emit('closed')">
    <el-form :model="model" label-width="80px" :inline="false" v-if="model">
      <!-- 名称 -->
      <el-form-item label="名称">
        <el-input v-model="model.name">
          <template #suffix>
            <ApplicationOne theme="outline" size="18" fill="#888" />
          </template>
        </el-input>
      </el-form-item>

      <!-- 文件选择 -->
      <el-form-item label="文件选择">
        <el-input placeholder="选择文件">
          <template #append>
            <el-button>
              <FolderOpen theme="outline" size="16" fill="#888" />
            </el-button>
          </template>
        </el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button @click="emit('closed')">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script setup lang="ts">
import useSection from '@/composables/useSection'
import { SectionModel } from '@/types/model'
import { ApplicationOne, FolderOpen } from '@icon-park/vue-next'
import { ElMessage } from 'element-plus'

const prop = defineProps<{
  visiable: boolean
  model: SectionModel | undefined
}>()

const emit = defineEmits(['closed'])
const { update } = useSection()

async function onSubmit() {
  await update(prop.model!.id!, {
    name: prop.model!.name,
  })
  ElMessage({
    type: 'success',
    message: '修改成功',
  })
  emit('closed')
}
</script>

<style></style>
